"precision mediump float;\n"
"uniform vec3 gAmbient;\n"
"uniform vec4 gLightPosX;\n"
"uniform vec4 gLightPosY;\n"
"uniform vec4 gLightPosZ;\n"
"uniform vec3 gEyePosition;\n"
"uniform vec4 gSpecularColor;\n"
"uniform vec3 gLightColor0;\n"
"uniform vec3 gLightColor1;\n"
"uniform vec3 gLightColor2;\n"
"uniform vec3 gLightColor3;\n"
"uniform vec3 gEmissionColor;\n"
"uniform sampler2D gSampler;\n"
"varying vec4 v_color;\n" //頂点カラー
"varying vec2 v_texCoord;\n"
"varying vec3 v_position;\n"
"varying vec3 v_normal;\n"
"void main() {\n"
//反射ベクタの生成(ただし視線ベクタに対して)
"  vec3 ev = gEyePosition - v_position;\n"
"  vec3 nv = normalize( v_normal );\n"
"  vec3 rv = 2.0 * nv * dot( nv, ev ) - ev;\n"
//ライトベクタの生成
"  vec4 lvX, lvY, lvZ;\n"
"  lvX = gLightPosX - v_position.xxxx;\n"
"  lvY = gLightPosY - v_position.yyyy;\n"
"  lvZ = gLightPosZ - v_position.zzzz;\n"
//ライトベクタと反射ベクタの内積
"  vec4 s;\n"
"  s = lvX * rv.xxxx;\n"
"  s += lvY * rv.yyyy;\n"
"  s += lvZ * rv.zzzz;\n"
//指数関数を取る前に |L||R|で除す必要あり。
"  vec4 lvL2 = lvX * lvX;\n" //ライトベクタ二乗長さ
"  lvL2 += lvY * lvY;\n"
"  lvL2 += lvZ * lvZ;\n"
"  lvL2 += 0.0001;\n" //0割り防止
"  vec4 rcpLvL = inversesqrt( lvL2 );\n" //長さの逆数
"  vec4 rvL2 = vec4( dot( rv, rv ) );\n"
"  s *= inversesqrt( lvL2 * rvL2 );\n"
"  s = max( vec4( 0 ), s );\n"
"  s = pow( s, gSpecularColor.wwww );\n"
"  s *= rcpLvL;\n" //さらにライト距離で除す
//"  s = max( vec4( 0 ), s );\n" // GPUによってsがマイナスまで行く気配
//ディフューズ項を計算する。
"  vec4 d = lvX * nv.xxxx;\n"
"  d += lvY * nv.yyyy;\n"
"  d += lvZ * nv.zzzz; \n"
"  d *= rcpLvL * rcpLvL;\n"
"  d = max( vec4( 0 ), d );\n" //これを|L|^2で除する。
// アンビエント
"  vec3 dc = gAmbient;\n"
"  dc += gLightColor0 * d.x;\n"
"  dc += gLightColor1 * d.y;\n"
"  dc += gLightColor2 * d.z;\n"
"  dc += gLightColor3 * d.w;\n"
"  vec3 sc = vec3( 0 );\n"
"  sc += gLightColor0 * s.x;\n"
"  sc += gLightColor1 * s.y;\n"
"  sc += gLightColor2 * s.z;\n"
"  sc += gLightColor3 * s.w;\n"
// サンプラとスペキュラ
"  vec4 c = v_color * texture2D( gSampler, v_texCoord );\n"
"  c.xyz *= dc.xyz;\n"
"  c.xyz += sc * gSpecularColor.xyz;\n"
"  c.xyz += gEmissionColor.xyz;\n"
"  gl_FragColor = c;\n"
"}\n"
